package com.jason.system.common.jwt;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.shiro.authc.AuthenticationToken;

/**
 * @author jie
 * @version 1.0
 * success come from self-discipline
 * @date 2021/3/23 10:53
 */

@Data
@NoArgsConstructor
public class JwtToken implements AuthenticationToken {

  private static String head = "Bearer";

  private String token;

  public JwtToken(String token){
    if(token.contains(head)){
      token = token.substring(7);
    }
    this.token = token;
  }

  /**
   * token作为principle
   * @return token
   */
  @Override
  public Object getPrincipal() {
    return this.token;
  }

  /**
   * 由于getPrincipal没返回username，而是返回token，所以credentials设置为token也可
   * @return token
   */
  @Override
  public Object getCredentials() {
    return this.token;
  }
}
